package com.ruoyi.project.system.sending.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.sending.domain.TbPlcSending;
import com.ruoyi.project.system.sending.service.ITbPlcSendingService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 向plc发送信息Controller
 * 
 * @author kangjie
 * @date 2020-01-08
 */
@Controller
@RequestMapping("/system/sending")
public class TbPlcSendingController extends BaseController
{
    private String prefix = "system/sending";

    @Autowired
    private ITbPlcSendingService tbPlcSendingService;

    @RequiresPermissions("system:sending:view")
    @GetMapping()
    public String sending()
    {
        return prefix + "/sending";
    }

    /**
     * 查询向plc发送信息列表
     */
    @RequiresPermissions("system:sending:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbPlcSending tbPlcSending)
    {
        startPage();
        List<TbPlcSending> list = tbPlcSendingService.selectTbPlcSendingList(tbPlcSending);
        return getDataTable(list);
    }

    /**
     * 导出向plc发送信息列表
     */
    @RequiresPermissions("system:sending:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbPlcSending tbPlcSending)
    {
        List<TbPlcSending> list = tbPlcSendingService.selectTbPlcSendingList(tbPlcSending);
        ExcelUtil<TbPlcSending> util = new ExcelUtil<TbPlcSending>(TbPlcSending.class);
        return util.exportExcel(list, "sending");
    }

    /**
     * 新增向plc发送信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存向plc发送信息
     */
    @RequiresPermissions("system:sending:add")
    @Log(title = "向plc发送信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbPlcSending tbPlcSending)
    {
        return toAjax(tbPlcSendingService.insertTbPlcSending(tbPlcSending));
    }

    /**
     * 修改向plc发送信息
     */
    @GetMapping("/edit/{id}}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TbPlcSending tbPlcSending = tbPlcSendingService.selectTbPlcSendingById(id);
        mmap.put("tbPlcSending", tbPlcSending);
        return prefix + "/edit";
    }

    /**
     * 修改保存向plc发送信息
     */
    @RequiresPermissions("system:sending:edit")
    @Log(title = "向plc发送信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbPlcSending tbPlcSending)
    {
        return toAjax(tbPlcSendingService.updateTbPlcSending(tbPlcSending));
    }

    /**
     * 删除向plc发送信息
     */
    @RequiresPermissions("system:sending:remove")
    @Log(title = "向plc发送信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbPlcSendingService.deleteTbPlcSendingByIds(ids));
    }
}
